package com.xiaoxu.intranetweb.mybatisplusSzappdb.vo.Constructor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.CCompanys;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.CProductsInfo;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.TPriceRecord;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.service.ICCompanysService;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.service.ICProductsInfoService;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.vo.GetPriceRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TPriceRecord2GetPriceRecordVo {
    @Autowired
    private ICProductsInfoService cProductsInfoService;
    @Autowired
    private ICCompanysService cCompanysService;
    public GetPriceRecordVo priceRecord2GetPriceRecordVo(TPriceRecord tPriceRecord){
        GetPriceRecordVo getPriceRecordVo = new GetPriceRecordVo();
        getPriceRecordVo.setId(tPriceRecord.getId());
        getPriceRecordVo.setPdtId(tPriceRecord.getPdtId());
        QueryWrapper<CProductsInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",tPriceRecord.getPdtId());
        CProductsInfo cProductsInfo = cProductsInfoService.getOne(queryWrapper);
        getPriceRecordVo.setPdtName(cProductsInfo.getPdtinfPdt());
        getPriceRecordVo.setPrice(tPriceRecord.getPrice());
        getPriceRecordVo.setCpyId(tPriceRecord.getCpyId());
        QueryWrapper< CCompanys> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("id",tPriceRecord.getCpyId());
        CCompanys cCompanys = cCompanysService.getOne(queryWrapper1);
        getPriceRecordVo.setCpyName(cCompanys.getCpyCo()+"."+cCompanys.getCpyChico());
        getPriceRecordVo.setCreatorName(tPriceRecord.getCreatorName());
        getPriceRecordVo.setCreatorId(tPriceRecord.getCreatorId());
        getPriceRecordVo.setCreateTime(tPriceRecord.getCreateTime());
        getPriceRecordVo.setDataFrom(tPriceRecord.getDataFrom());
        getPriceRecordVo.setRemark(tPriceRecord.getRemark());
        getPriceRecordVo.setRecordNo(tPriceRecord.getRecordNo());
        return getPriceRecordVo;
    }

}
